package org.geek4j.test;

import java.util.Map;

import org.apache.http.client.fluent.Content;
import org.apache.http.client.fluent.Request;
import org.junit.Test;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author Geek4J
 * @description Tester
 */
@Slf4j
public class LocationViaIP {

	@Test
	public void ip2Location() throws Exception {
		String ip2Location = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json";
		String ip = "8.8.8.8";
		Content content = Request.Get(ip2Location + "&ip=" + ip).execute().returnContent();
		Map<String, String> kvs = new Gson().fromJson(content.asString(), new TypeToken<Map<String, String>>() {}.getType());
		log.error(content.asString());
		log.error(kvs.get("country") + kvs.get("province") + kvs.get("city"));
	}
}